package com.example.demo.pojo.vo;

import com.example.demo.pojo.entity.QuestionBank;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.aspectj.weaver.patterns.TypePatternQuestions;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @Description: 试卷题种类与题目关系下的题目信息
 * @author: fjh
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class ExamQuestionVO {
    private Integer questionId;
    private Integer indexId;
    //题目信息
    private String questionName;
    private String options;
    private Double score;
    private String difficulty;
    private String parse;
    private String label;
    private Integer categoryId;
    //html展示信息
    private String htmlName;
    private String htmlOption;
    private String htmlParse;
    //处理数据
    private List<String> optionList=new ArrayList<>();
    private List<String> htmlOptionsList=new ArrayList<>();
    public void initQuestion(QuestionBank questionBank){
        this.questionId=questionBank.getId();
        this.questionName=questionBank.getName();
        this.options=questionBank.getOptions();
        this.score=questionBank.getScore();
        this.difficulty=questionBank.getDifficulty();
        this.parse=questionBank.getParse();
        this.label=questionBank.getLabel();
        this.htmlParse=questionBank.getHtmlParse();
        this.htmlName=questionBank.getHtmlName();
        this.htmlOption=questionBank.getHtmlOption();
        this.categoryId=questionBank.getCategory();
        initOptions(questionBank.getOptions(),questionBank.getHtmlOption());
    }
    public void initOptions(String options,String htmlOptions){
        if(options!=null){
            String[]option=options.split("\\|");
            this.optionList.addAll(Arrays.asList(option));
        }
        if(htmlOptions!=null){
            String[]htmlOption=htmlOptions.split("\\|");
            this.htmlOptionsList.addAll(Arrays.asList(htmlOption));
        }
    }
}
